#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int triangleNumber(vector<int> &nums)
{
    sort(nums.begin(), nums.end());
    int n = nums.size();
    int cnt = 0;
    for (int i = n - 1; i >= 2; i--)
    {
        int right = i - 1;
        int left = 0;
        while (left < right)
        {
            if (nums[left] + nums[right] > nums[i])
            {
                cnt += right - left;
                right--;
            }
            else
            {
                left++;
            }
        }
    }
    return cnt;
}

int main()
{
    vector<int> v = {2, 2, 3, 4};
    cout << triangleNumber(v) << endl;
    return 0;
}